﻿using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;

using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace NRails
{
  public class CompileTimeConfigLocator : ConfigLocator
  {
    path : string;

    public this(prjPath : string)
    {
      path = FileInfo(prjPath).DirectoryName;
    }

    public override GetLocation() : string
    {
      def location = match (HttpContext.Current == null)
      {
        | true => getConfigLocation([path])
        | false => HttpContext.Current.Server.MapPath("~/nrails.cfg")
      } 

      when (location == null)
        throw FileNotFoundException($"nrails.cfg not found in $path");

      location
    }
  }
}
